/*
 * Copyright (c) 2013-2018 上海汇数数据. All rights reserved.
 * @(#) DateTimeKt.java 2018-08-20 09:54
 */

package cn.jh.common.core.time;

import com.google.common.collect.Range;
import org.jetbrains.annotations.NotNull;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;


/**
 * {@code java.time.*} 工厂工具类。
 *
 * @author Fuchun
 * @since 1.0
 */
public class DateTimeKt {

    /**
     * 计算并返回给定日期当天的{@code LocalDateTime} 表示的一天的范围：{@code 00:00:00.000000000 ~ 23:59:59.999999999}
     * <pre>{@code
     * Range<LocalDateTime> range = DateTimeKt.dayOfRange(LocalDate.now());
     * LocalDateTime from = range.lowerEndpoint();
     * LocalDateTime to = range.upperEndpoint();
     * }</pre>
     *
     * @param date 日期。
     * @return 返回给定日期当天的{@code LocalDateTime} 表示的一天的范围。
     */
    @NotNull
    public static Range<LocalDateTime> dayOfRange(@NotNull LocalDate date) {
        // {LocalDate} '00:00:00.000'
        LocalDateTime from = date.atStartOfDay();
        // {LocalDate} '23:59:59.999999999'
        LocalDateTime to = date.atTime(LocalTime.MAX);
        return Range.closed(from, to);
    }



    private DateTimeKt() {}
}
